﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;

namespace testSimpleDLL
{
    public partial class Form1 : Form
    {
        string dll_path = Directory.GetCurrentDirectory() + "\\PCANLINClass.dll";
        Boolean result = false;
        string para;

        public Form1()
        {
            InitializeComponent();
        }



        private void button1_Click(object sender, EventArgs e)
        {
            


            try
            {
                Assembly PCANLIN = Assembly.LoadFrom(dll_path);
                //Assembly.LoadFile(dll_path);
                Type iPCANLIN = PCANLIN.GetType("PCANLINClass.PCANLIN");
                //Type shell = ESYSShell.GetType("ESYSShell.Shell");
                object objPCANLIN = Activator.CreateInstance(iPCANLIN, this.para);
                MethodInfo iPCANLIN_openPort = iPCANLIN.GetMethod("openPort");
                result = (bool)iPCANLIN_openPort.Invoke(objPCANLIN, new object[] { });
            }
            catch (Exception ee)
            {

                MessageBox.Show(ee.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                Assembly PCANLIN = Assembly.LoadFrom(dll_path);
                //Assembly.LoadFile(dll_path);
                Type iPCANLIN = PCANLIN.GetType("PCANLINClass.PCANLIN");
                //Type shell = ESYSShell.GetType("ESYSShell.Shell");
                object objPCANLIN = Activator.CreateInstance(iPCANLIN,para);
                MethodInfo iPCANLIN_closePort = iPCANLIN.GetMethod("closePort");
                result = (bool)iPCANLIN_closePort.Invoke(objPCANLIN, new object[] { });
            }
            catch (Exception ee)
            {

                MessageBox.Show(ee.Message);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.para = "COM10";
        }
    }
}
